//
//  PingJiaSuccessVC.m
//  QoilPublic
//
//  Created by SunChao on 2018/3/2.
//  Copyright © 2018年 孙超. All rights reserved.
//

#import "PingJiaSuccessVC.h"
#import "HomePingJiaVC.h"
#import "QPointShopVC.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
@interface PingJiaSuccessVC ()
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UIButton *submitBtn;
@property (weak, nonatomic) IBOutlet UIImageView *scoreImg;
@property (nonatomic,strong)NSArray *orderArray;

@end

@implementation PingJiaSuccessVC


- (IBAction)submitAction:(UIButton *)sender {
    
    [self gainOrderInfo];
    
}
- (void)gainOrderInfo{
    
    NSString *url = [QParamService urlWithAction:@"order/findUserOrderEvaluate"];
   
    NSDictionary *params = [QParamService GainStarText];
    
    [[QHttpManager sharedManager] POST:url parameterMD5:params completion:^(NSData *data, NSDictionary *dict, NSError *error) {
        if(error){
            
            return ;
            
        }
        
        QBaseModel *basModel = [QBaseModel objectFromDict:dict];
        
        if([basModel.result isEqualToString:@"success"]){
            self.orderArray  =   basModel.items;
            if (self.orderArray.count>0) {
                
                HomePingJiaVC *vc = [[HomePingJiaVC alloc]init];
                UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
                [self presentViewController:nav animated:YES completion:nil];
                
            }else{
                
                [[NSNotificationCenter defaultCenter]postNotificationName:@"HomePingJiaNotification" object:nil];
            }
           
            
        }else{
            
            
        }
    }];
}
- (IBAction)XBtnAction:(UIButton *)sender {
    
    [self gainOrderInfo];
    
}
- (IBAction)ShareAction:(UIButton *)sender {
    
    CLog(@"微信");
    NSString *url = [NSString stringWithFormat:@"http://www.ydaol.com/oilWX_api/activity/evaluate/sharechannel.html?orderId=%@",self.orderId];
    
    [UMSocialData defaultData].extConfig.wechatSessionData.title = @"【油到了】第3个领取的人红包最大！";
    
    [UMSocialData defaultData].extConfig.wechatSessionData.url =url;

        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:@"分享新用户最高领取50元红包，看手速的时候到啦~" image:[UIImage imageNamed:@"loginlogo_image"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            
            if (response.responseCode == UMSResponseCodeSuccess) {
             
                CLog(@"分享成功！");
                
            }else{
                
                CLog(@"分享失败");
                
            }
            
            
        }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.submitBtn.layer.cornerRadius = 3;
    self.submitBtn.layer.masksToBounds = YES;
    UIButton *button = [UIButton buttonWithType:0];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, kScreenHeight-121, kScreenWidth, 121);
    button.backgroundColor = [UIColor clearColor];
    [self.view addSubview:button];
    self.scoreImg.userInteractionEnabled = YES;
    
}
- (void)buttonAction:(UIButton *)button{
    
    QPointShopVC * vc = [[QPointShopVC alloc]init];

    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
